package com.lw.extraceim.ui.activity.tp;

import androidx.appcompat.app.AlertDialog;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.lw.extraceim.R;
import com.lw.extraceim.model.TransPackage;
import com.lw.extraceim.ui.activity.base.BaseActivity;
import com.lw.extraceim.ui.fragments.TaskFragment;

public class TransportInfoActivity extends BaseActivity {
    private TextView mtvTransportNumber,mtvTransportFrom,mtvTransportTo,mtvTransportToLocation;
    private Button mButtonEnsure;//确认收件人收到快递的按钮
    private ImageButton mImageButtonBack;
    private boolean isEnsure=false;//收件人是否确认收货了
    String transportNumber;//快件编号
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_transport_info);
        mtvTransportTo=findViewById(R.id.textview_transport_to);
        mtvTransportFrom=findViewById(R.id.textview_transport_from);
        mtvTransportNumber=findViewById(R.id.textview_transport_number);
        mtvTransportToLocation=findViewById(R.id.textview_transport_to_location);
        mButtonEnsure=findViewById(R.id.btn_ensure);
        mImageButtonBack=findViewById(R.id.imagebutton_back);
    }

    @Override
    public void initData() {
        Intent intent=getIntent();
        transportNumber=intent.getStringExtra("expressSheetID");
        mtvTransportNumber.setText(transportNumber);
    }

    @Override
    public void refreshUI() {

    }

    @Override
    public void initEvent() {
        mButtonEnsure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });
        mImageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    private void showDialog()
    {
        AlertDialog.Builder builder=new AlertDialog.Builder(TransportInfoActivity.this);
        builder.setTitle("提示")
                .setMessage("确认收货?")
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                isEnsure=true;//修改bool确认收货
                Intent intent=new Intent(TransportInfoActivity.this, TaskFragment.class);
                intent.putExtra("isEnsure",isEnsure);
                intent.putExtra("expressSheetID",transportNumber);
                setResult(TaskFragment.RESULT_FROM_TRANSPORTINFOACTIVITY,intent);
                finish();
            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).show();
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    public static void actionStart(Context context, TransPackage transPackage){
        Intent intent = new Intent(context,TransportInfoActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("package",transPackage);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}
